package com.nuorui.module.system.controller;


import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.MenuForm;
import com.nuorui.module.system.domain.query.MenuQueryForm;
import com.nuorui.module.system.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 菜单
 *
 * @author
 * @date 2021-12-14 09:32:44
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_MENU)
public class MenuController {

    private final MenuService menuService;

    @GetMapping("/menus")
    @ApiOperation(value = "查询菜单列表", notes = "查询菜单列表")
    public ResponseDTO getMenuGroup(@RequestBody @Valid MenuQueryForm queryForm) {
        return menuService.getMenuGroup(queryForm);
    }

    @GetMapping("/menus/tree")
    @ApiOperation(value = "查询菜单树", notes = "查询菜单树")
    public ResponseDTO getMenuTree(@RequestBody @Valid MenuQueryForm queryForm) {
        return menuService.getMenuTree(queryForm);
    }

    @PostMapping("/menus")
    @ApiOperation(value = "添加菜单", notes = "添加菜单")
    public ResponseDTO saveMenu(@RequestBody @Valid MenuForm menuForm) {
        return menuService.saveMenu(menuForm);
    }

    @PutMapping("/menus/{menuId}")
    @ApiOperation(value = "添加菜单", notes = "添加菜单")
    public ResponseDTO updateMenu(@PathVariable("menuId") Long menuId, @RequestBody @Valid MenuForm menuForm) {
        return menuService.updateMenu(menuId, menuForm);
    }

    @DeleteMapping("/menus")
    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    public ResponseDTO batchDelete(@RequestParam("menuIdList") List<Long> menuIdList) {
        return menuService.batchDelete(menuIdList);
    }
}
